import instance from "@/utils/http";

// 获取轮播图数据
export function getLoop(pageNum, pageSize) {
  return instance.get(`/carousel?pageNum`, {
    params: { pageNum, pageSize },
  });
}
// 获取课程列表
export function getList(params) {
  return instance.get("/course/search", {
    params: {
      ...params,
    },
  });
}
// 获取课程分类信息
export function getClassifyList() {
  return instance.get("/topic");
}

// 获取某个课程的详情信息
export function getCourseDetail(courseId) {
  return instance.get(`/course/detail/${courseId}`);
}

/* 获取头条精选 */
export function getHeadlineList(params) {
  return instance.post(
    `/api/weChat/applet/article/list?pageNum=1&pageSize=5`,
    params
  );
}

// 获取底部信息
export function getFooterInfo() {
  let params = new URLSearchParams();
  params.append("dictType", "blogroll");
  params.append("pageNum", "1");
  params.append("pageSize", "5");
  params.append("orderByColumn", "dictSort");
  params.append("isAsc", "asc");
  params.append("Content-Type", "application/x-www-form-urlencoded");
  return instance.post("/api/system/dict/data/list/open", params);
}

// 获取课程评论
export function getCourseComment(courseId, pageSize, pageNum) {
  return instance.get(
    `/api/pc/comment/commentList/course/${courseId}?pageNum=${pageNum}&pageSize=${pageSize}`
  );
}
//登录
export function getLoginInfo(username, password) {
  let params = new URLSearchParams();
  params.append("username", username);
  params.append("password", password);
  params.append("rememberMe", false);
  return instance.post(`/login`, params);
}

// 获取搜索结果
export function getSearchResult(params) {
  return instance.get("/course/search", {
    params: {
      ...params,
    },
  });
}
// 用户登出
export function logout() {
  return instance.get(`/api/pcUser/logout`);
}

// 获取验证码
export function getCheckCode(mobile) {
  return instance.get(`/api/pcUser/login/send/code/${mobile}`);
}

// 获取用户信息
export function getLoginUserInfo() {
  return instance.get(`/api/pcUser/login-user/info`);
}

//更新用户信息
export function updateUserInfo(data) {
  return instance.put("/user", data);
}
// 获取购物车信息
export function getUserShoppingCartInfo(status) {
  return instance.get(
    `/api/weChat/applet/shoppingCart/my/list?status=${status}`
  );
}

// 删除购物车课程
export function deleteChartCourse(shoppingCartId) {
  return instance.get(
    `/api/weChat/applet/shoppingCart/remove/${shoppingCartId}`
  );
}
// 添加购物车课程
export function addChartCourse(courseId) {
  return instance.get(
    `/api/weChat/applet/shoppingCart/join/shoppingCart/${courseId}`
  );
}
// 获取直播课程
export function getLiveCourseInfo(pageNum, pageSize) {
  // /api/pc/liveCourseInfo/list?pageSize=4&pageNum=1
  return instance.post(
    `/api/pc/liveCourseInfo/list?pageSize=${pageSize}&pageNum=${pageNum}`
  );
}
// 获取销量排行榜的课程信息
export function getSellingBestCourseInfo() {
  // /api/best-selling/course/list
  return instance.get(`/api/best-selling/course/list`);
}
